package com.zt.ztyh.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zt.ztyh.admin.service.FundsService;
import com.zt.ztyh.admin.service.FundsinfoService;
import com.zt.ztyh.model.common.Result;
import com.zt.ztyh.model.common.ResultCodeEnum;
import com.zt.ztyh.model.dto.FundsDto;
import com.zt.ztyh.model.entity.Funds;

import com.zt.ztyh.model.entity.Fundsinfo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/funds")
public class FundsAdminController {

    @Autowired
    private FundsService fundsService;

    @Autowired
    private FundsinfoService fundsinfoService;

    @GetMapping("/findAll/{page}/{limit}")
    @Operation(summary = "理财产品列表")
    public Result<Page<Funds>> findAllFunds(@PathVariable("page") Integer page,
                                              @PathVariable("limit") Integer limit,
                                              FundsDto fundsDto
    ) {
        return Result.build(fundsService.findAllFunds(page, limit,fundsDto), ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/")
    @Operation(summary = "添加修改理财产品")
    public Result addFunds(@RequestBody FundsDto funds) {
        fundsService.insertOrUpdate(funds);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("/{fid}")
    public Result deleteFunds(@PathVariable("fid") Long fid) {
        fundsService.removeById(fid);
        fundsinfoService.removeById(fid);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/getFundsInfo/{id}")
    @Operation(summary = "查询商品信息")
    public Result<Fundsinfo> getFundsInfo(@PathVariable("id") Long id) {
        return Result.build(fundsinfoService.getById(id), ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/updateState/{fid}")
    @Operation(summary = "修改状态")
    public Result updateState(@PathVariable("fid") Long fid) {
        fundsinfoService.updateState(fid);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

}
